package ru.ibrae.mchs.radiation.GUI;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ObjInfo.java
 *
 * Created on 06.07.2010, 16:56:14
 */


import ru.ibrae.mchs.radiation.entities.CrossZon;
import ru.ibrae.mchs.radiation.entities.DicTime;
import ru.ibrae.mchs.radiation.entities.Geoobject;
import ru.ibrae.mchs.radiation.entities.Pokazatel;
import ru.ibrae.mchs.radiation.entities.Result;
import ru.ibrae.mchs.radiation.entities.controllers.CommentJpaController;
import ru.ibrae.mchs.radiation.entities.controllers.DicTimeJpaController;
import ru.ibrae.mchs.radiation.entities.controllers.GeoobjectJpaController;
import ru.ibrae.mchs.radiation.entities.controllers.PokazatelJpaController;
import ru.ibrae.mchs.radiation.entities.controllers.ResultJpaController;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import javax.swing.table.TableColumnModel;

/**
 *
 * @author murr
 */
public class ObjInfo extends javax.swing.JDialog {

    private Integer geoobjId;
    private ArrayList<DicTime> dicTimesSGED = new ArrayList<DicTime>();
    private PokazatelJpaController pjc = new PokazatelJpaController();
    private ResultJpaController rjc = new ResultJpaController();
    private ArrayList<DicTime> downTableTimes = new ArrayList<DicTime>();
    private DicTimeJpaController dtjc = new DicTimeJpaController();

    /** Creates new form ObjInfo */
    public ObjInfo(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        jXTable3.addMouseListener(new MouseListener() {

            private String res;
            private CommentJpaController cjc = new CommentJpaController();

            @Override
            public void mouseClicked(MouseEvent e) {
                forwardEventToButton(e);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                //forwardEventToButton(e);
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                //forwardEventToButton(e);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                //forwardEventToButton(e);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                //forwardEventToButton(e);
            }

            private void forwardEventToButton(MouseEvent e) {
                TableColumnModel columnModel = jXTable3.getColumnModel();
                int col = columnModel.getColumnIndexAtX(e.getX());
                int row = e.getY() / jXTable3.getRowHeight();
                if (col != 0 && jXTable3.getValueAt(row, col) != null) {
                    res = (String) jXTable3.getValueAt(row, col);
                    if (!res.equals("")) {
                        jXTable3.getColumnExt("Служебная, не открывать").setVisible(true);
                        String comment = rjc.getComment(dtjc.findDicTime((Integer) jXTable3.getValueAt(row, 2)).getIdTime(), geoobjId, 1);
                        jTextPane2.setText(comment);
                        jXTable3.getColumnExt(2).setVisible(false);
                    }
                } else {
                    jTextPane2.setText("");
                }
            }
        });
    }

    public void setGeoobjId(Integer geoobjId) {
        this.geoobjId = geoobjId;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jXTable2 = new org.jdesktop.swingx.JXTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jXTable3 = new org.jdesktop.swingx.JXTable();
        jButton1 = new javax.swing.JButton();
        jXCollapsiblePane1 = new org.jdesktop.swingx.JXCollapsiblePane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTable1 = new org.jdesktop.swingx.JXTable();
        jToggleButton1 = new javax.swing.JToggleButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jXTable4 = new org.jdesktop.swingx.JXTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jTextField4.setEditable(false);
        jTextField4.setText("jTextField4");
        jTextField4.setName("jTextField4"); // NOI18N

        jTextField5.setEditable(false);
        jTextField5.setText("jTextField5");
        jTextField5.setName("jTextField5"); // NOI18N

        jTextField3.setEditable(false);
        jTextField3.setText("jTextField3");
        jTextField3.setName("jTextField3"); // NOI18N

        jLabel3.setText("Название поселения");
        jLabel3.setName("jLabel3"); // NOI18N

        jTextField6.setEditable(false);
        jTextField6.setText("jTextField6");
        jTextField6.setName("jTextField6"); // NOI18N

        jLabel4.setText("Название субъекта федерации");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel1.setText("Навание объекта");
        jLabel1.setName("jLabel1"); // NOI18N

        jTextField1.setEditable(false);
        jTextField1.setText("jTextField1");
        jTextField1.setName("jTextField1"); // NOI18N

        jTextField2.setEditable(false);
        jTextField2.setText("jTextField2");
        jTextField2.setName("jTextField2"); // NOI18N

        jLabel2.setText("Название района");
        jLabel2.setName("jLabel2"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jXTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Период", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3"
            }
        ));
        jXTable2.setColumnControlVisible(true);
        jXTable2.setName("jXTable2"); // NOI18N
        jScrollPane2.setViewportView(jXTable2);
        jXTable2.getColumnModel().getColumn(1).setHeaderValue(pjc.findPokazatel(2).getShortPok());
        jXTable2.getColumnModel().getColumn(2).setHeaderValue(pjc.findPokazatel(3).getShortPok());
        jXTable2.getColumnModel().getColumn(3).setHeaderValue(pjc.findPokazatel(4).getShortPok());

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jXTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Период", "Население", "Служебная, не открывать"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jXTable3.setColumnControlVisible(true);
        jXTable3.setColumnSelectionAllowed(true);
        jXTable3.setName("jXTable3"); // NOI18N
        jXTable3.getTableHeader().setReorderingAllowed(false);
        jScrollPane3.setViewportView(jXTable3);
        jXTable3.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jXTable3.getColumnModel().getColumn(2).setMinWidth(0);
        jXTable3.getColumnModel().getColumn(2).setMaxWidth(1);

        jButton1.setText("OK");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jXCollapsiblePane1.setCollapsed(true);
        jXCollapsiblePane1.setName("jXCollapsiblePane1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jXTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Начало", "Окончание", "Статус"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jXTable1.setName("jXTable1"); // NOI18N
        jXTable1.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jXTable1);

        javax.swing.GroupLayout jXCollapsiblePane1Layout = new javax.swing.GroupLayout(jXCollapsiblePane1.getContentPane());
        jXCollapsiblePane1.getContentPane().setLayout(jXCollapsiblePane1Layout);
        jXCollapsiblePane1Layout.setHorizontalGroup(
            jXCollapsiblePane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 766, Short.MAX_VALUE)
            .addGroup(jXCollapsiblePane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE))
        );
        jXCollapsiblePane1Layout.setVerticalGroup(
            jXCollapsiblePane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 107, Short.MAX_VALUE)
            .addGroup(jXCollapsiblePane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jXCollapsiblePane1Layout.createSequentialGroup()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jToggleButton1.setText("Просмотреть статусы зоны");
        jToggleButton1.setName("jToggleButton1"); // NOI18N
        jToggleButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jToggleButton1MouseClicked(evt);
            }
        });

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jXTable4.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Период", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3", "java.lang.Object@5aa249f3"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jXTable4.setName("jXTable4"); // NOI18N
        jScrollPane4.setViewportView(jXTable4);
        jXTable4.getColumnModel().getColumn(1).setHeaderValue(pjc.findPokazatel(5).getShortPok());
        jXTable4.getColumnModel().getColumn(2).setHeaderValue(pjc.findPokazatel(6).getShortPok());
        jXTable4.getColumnModel().getColumn(3).setHeaderValue(pjc.findPokazatel(7).getShortPok());
        jXTable4.getColumnModel().getColumn(4).setHeaderValue(pjc.findPokazatel(8).getShortPok());
        jXTable4.getColumnModel().getColumn(5).setHeaderValue(pjc.findPokazatel(14).getShortPok());
        jXTable4.getColumnModel().getColumn(6).setHeaderValue(pjc.findPokazatel(15).getShortPok());
        jXTable4.getColumnModel().getColumn(7).setHeaderValue(pjc.findPokazatel(16).getShortPok());
        jXTable4.getColumnModel().getColumn(8).setHeaderValue(pjc.findPokazatel(17).getShortPok());
        jXTable4.getColumnModel().getColumn(9).setHeaderValue(pjc.findPokazatel(18).getShortPok());
        jXTable4.getColumnModel().getColumn(10).setHeaderValue(pjc.findPokazatel(19).getShortPok());
        jXTable4.getColumnModel().getColumn(11).setHeaderValue(pjc.findPokazatel(20).getShortPok());
        jXTable4.getColumnModel().getColumn(12).setHeaderValue(pjc.findPokazatel(21).getShortPok());

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        jTextPane1.setName("jTextPane1"); // NOI18N
        jScrollPane5.setViewportView(jTextPane1);

        jScrollPane6.setName("jScrollPane6"); // NOI18N

        jTextPane2.setName("jTextPane2"); // NOI18N
        jScrollPane6.setViewportView(jTextPane2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                .addGap(12, 12, 12)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jLabel4)
                .addGap(12, 12, 12)
                .addComponent(jTextField6, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE)
                .addGap(12, 12, 12))
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addGap(6, 6, 6)
                .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addGap(12, 12, 12))
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addGap(6, 6, 6)
                .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addGap(12, 12, 12))
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE)
                .addGap(12, 12, 12))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToggleButton1)
                .addContainerGap())
            .addComponent(jXCollapsiblePane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 670, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 742, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel1))
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel2))
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel3))
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel4))
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jXCollapsiblePane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jToggleButton1)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane3, 0, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 530, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER, false)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jScrollPane2, jScrollPane3});

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jScrollPane6});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        // TODO add your handling code here:
        GeoobjectJpaController controller = new GeoobjectJpaController();
        Geoobject g = controller.findGeoobject(geoobjId);
        jTextField1.setText(g.getNameNp());
        if (g.getRajon() != null && !g.getRajon().getName2().equalsIgnoreCase("") && g.getRajon().getName2() != null) {
            jTextField2.setText(g.getRajon().getName2());
        } else {
            jTextField2.setText("");
        }
        if (g.getRajonOld() != null && !g.getRajonOld().getPlacename().equalsIgnoreCase("") && g.getRajonOld().getPlacename() != null) {
            jTextField3.setText(g.getRajonOld().getPlacename());
        } else {
            jTextField3.setText("");
        }
        if (g.getGSPos() != null && !g.getGSPos().getName2().equalsIgnoreCase("") && g.getGSPos().getName2() != null) {
            jTextField4.setText(g.getGSPos().getName2());
        } else {
            jTextField4.setText("");
        }
        if (g.getSelsovet() != null && !g.getSelsovet().getPlacename().equalsIgnoreCase("") && g.getSelsovet().getPlacename() != null) {
            jTextField5.setText(g.getSelsovet().getPlacename());
        } else {
            jTextField5.setText("");
        }
        jTextField6.setText(g.getSubjectRf().getName1());
        ArrayList<CrossZon> zons = new ArrayList<CrossZon>(g.getCrossZonSet());
        Collections.sort(zons, new Comparator<CrossZon>() {

            @Override
            public int compare(CrossZon t, CrossZon t1) {
                return t.getCrossZonPK().getDateZon0().compareTo(t1.getCrossZonPK().getDateZon0());
            }
        });
        for (int i = 0; i < zons.size(); i++) {
            CrossZon crossZon = zons.get(i);
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy");
            jXTable1.getModel().setValueAt(dateFormat.format(crossZon.getCrossZonPK().getDateZon0()), i, 0);
            if (crossZon.getDateZonn() != null) {
                jXTable1.getModel().setValueAt(dateFormat.format(crossZon.getDateZonn()), i, 1);
            } else {
                jXTable1.getModel().setValueAt("По настоящее время", i, 1);
            }

            jXTable1.getModel().setValueAt(crossZon.getDicZon().getStatusZon(), i, 2);
        }
        jXTable1.setColumnControlVisible(true);
        jXTable1.packAll();
        ArrayList<Result> results = new ArrayList<Result>(g.getResultSet());
        ArrayList<Pokazatel> pokazatels = new ArrayList<Pokazatel>(pjc.findPokazatelEntities());
        for (int i = 0; i < pokazatels.size(); i++) {
            Pokazatel pokazatel = pokazatels.get(i);
            ArrayList<Result> neededResults = new ArrayList<Result>();
            for (Result result : results) {
                if (result.getPokazatel().equals(pokazatel)) {
                    neededResults.add(result);
                }
            }
            Collections.sort(neededResults, new Comparator<Result>() {

                @Override
                public int compare(Result t, Result t1) {
                    return t.getDicTime().getIdTime() - t1.getDicTime().getIdTime();
                }
            });
            switch (pokazatel.getIdP()) {
                case 1: {
                    jXTable3.setRowSelectionAllowed(true);
                    for (int j = 0; j < neededResults.size(); j++) {
                        Result result = neededResults.get(j);
                        jXTable3.getModel().setValueAt(result.getRes(), j, 1);
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
                        jXTable3.getModel().setValueAt(dateFormat.format(result.getDicTime().getTN()) + " г.", j, 0);
                        jXTable3.getModel().setValueAt(result.getDicTime().getIdTime(), j, 2);
                    }
                    jXTable3.packAll();
                    jXTable3.getColumnExt(2).setVisible(false);
                    break;
                }
                case 2: {
                    ArrayList<Integer> timeIds = rjc.getIdTimeByPokazatel(new Pokazatel[]{pjc.findPokazatel(2), pjc.findPokazatel(3), pjc.findPokazatel(4)});
                    for (Integer integer : timeIds) {
                        dicTimesSGED.add(dtjc.findDicTime(integer));
                    }
                    for (int j = 0; j < dicTimesSGED.size(); j++) {
                        DicTime dicTime = dicTimesSGED.get(j);
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
                        jXTable2.getModel().setValueAt(dateFormat.format(dicTime.getTN()) + " г.", j, 0);
                        jXTable2.getModel().setValueAt(rjc.getResByIdPIdGeoobjeIdTime(pokazatel.getIdP(), geoobjId, dicTime.getIdTime()), j, 1);
                    }
                    break;
                }
                case 3: {
                    for (int j = 0; j < dicTimesSGED.size(); j++) {
                        DicTime dicTime = dicTimesSGED.get(j);
                        jXTable2.getModel().setValueAt(rjc.getResByIdPIdGeoobjeIdTime(pokazatel.getIdP(), geoobjId, dicTime.getIdTime()), j, 2);
                    }
                    break;
                }
                case 4: {
                    for (int j = 0; j < dicTimesSGED.size(); j++) {
                        DicTime dicTime = dicTimesSGED.get(j);
                        jXTable2.getModel().setValueAt(rjc.getResByIdPIdGeoobjeIdTime(pokazatel.getIdP(), geoobjId, dicTime.getIdTime()), j, 3);
                    }
                    jXTable2.packAll();
                    break;
                }
                default: {
                    loadOthers(pokazatel.getIdP());
                    break;
                }
            }
        }
        if (g.getComment() != null) {
            if (!g.getComment().getComentary().equals("")) {
                jTextPane1.setText(g.getComment().getComentary1());
            }

        }
    }//GEN-LAST:event_formComponentShown

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jToggleButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToggleButton1MouseClicked
        if (jToggleButton1.getText().equalsIgnoreCase("Просмотреть статусы зоны")) {
            jToggleButton1.setText("Скрыть статусы зоны");
        } else {
            jToggleButton1.setText("Просмотреть статусы зоны");
        }
        jXCollapsiblePane1.setCollapsed(!jXCollapsiblePane1.isCollapsed());
    }//GEN-LAST:event_jToggleButton1MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                ObjInfo dialog = new ObjInfo(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTextPane jTextPane2;
    private javax.swing.JToggleButton jToggleButton1;
    private org.jdesktop.swingx.JXCollapsiblePane jXCollapsiblePane1;
    private org.jdesktop.swingx.JXTable jXTable1;
    private org.jdesktop.swingx.JXTable jXTable2;
    private org.jdesktop.swingx.JXTable jXTable3;
    private org.jdesktop.swingx.JXTable jXTable4;
    // End of variables declaration//GEN-END:variables

    private void loadOthers(Integer idP) {
        if (idP == 5) {
            ArrayList<Pokazatel> allPokazatels = new ArrayList<Pokazatel>(pjc.findPokazatelEntities());
            ArrayList<Pokazatel> downTablePokazatels = new ArrayList<Pokazatel>();
            for (Pokazatel pokazatel : allPokazatels) {
                if (pokazatel.getIdP() > 4) {
                    downTablePokazatels.add(pokazatel);
                }
            }
            Pokazatel[] pokazatels = new Pokazatel[downTablePokazatels.size()];
            for (int i = 0; i < downTablePokazatels.size(); i++) {
                Pokazatel pokazatel = downTablePokazatels.get(i);
                pokazatels[i] = pokazatel;
            }
            ArrayList<Integer> idTimes = rjc.getIdTimeByPokazatel(pokazatels);
            for (Integer idTime : idTimes) {
                downTableTimes.add(dtjc.findDicTime(idTime));
            }
            for (int i = 0; i < downTableTimes.size(); i++) {
                DicTime dicTime = downTableTimes.get(i);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
                jXTable4.getModel().setValueAt(dateFormat.format(dicTime.getTN()), i, 0);
                jXTable4.getModel().setValueAt(rjc.getResByIdPIdGeoobjeIdTime(idP, geoobjId, dicTime.getIdTime()), i, 1);
            }
            jXTable4.packAll();
            jXTable4.setColumnControlVisible(true);
        } else if (idP > 5 && idP < 14) {
            for (int i = 0; i < downTableTimes.size(); i++) {
                DicTime dicTime = downTableTimes.get(i);
                jXTable4.getModel().setValueAt(rjc.getResByIdPIdGeoobjeIdTime(idP, geoobjId, dicTime.getIdTime()), i, idP - 4);
            }
        } else {
            for (int i = 0; i < downTableTimes.size(); i++) {
                DicTime dicTime = downTableTimes.get(i);
                jXTable4.getModel().setValueAt(rjc.getResByIdPIdGeoobjeIdTime(idP, geoobjId, dicTime.getIdTime()), i, idP - 9);
            }
        }
    }
}
